importScripts(
  "https://g.alicdn.com/mylib/lp-workbox-cdn/3.6.3-2/workbox/workbox-sw.js"
);

workbox.setConfig({
  debug: false
});
workbox.core.setLogLevel(workbox.core.LOG_LEVELS.debug);

workbox.skipWaiting();
workbox.clientsClaim();

workbox.precaching.suppressWarnings(false);
workbox.precaching.precacheAndRoute([]);

workbox.routing.registerRoute(
  /regSW\.pwa\.js/gi,
  workbox.strategies.networkOnly(),
  "GET"
);

workbox.routing.registerRoute(
  ({ url, event }) => {
    if (
      event.request.mode === "navigate" &&
      /(\/|index\.html)$/.test(url.href)
    ) {
      return true;
    } else {
      return false;
    }
  },
  workbox.strategies.cacheFirst({
    cacheName: "uxcore-pages",
    plugins: [
      new workbox.expiration.Plugin({
        maxEntries: 100,
        purgeOnQuotaError: true
      })
    ]
  })
);

workbox.routing.registerRoute(
  /\.png/,
  workbox.strategies.cacheFirst({
    cacheName: "uxcore-res"
  })
);
